package array;

import java.util.HashMap;

/**
 * 数组中两个数的和为目标值时返回这两个下标
 */
public class Demo2 {
    public static void main(String[] args) {

    }
    public static int[] method(int[] arr,int target){
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < arr.length; i++) {
            if (map.containsKey(target-arr[i])){
                return new int[]{i,map.get(target-arr[i])};
            }
            map.put(arr[i],i);
        }
        return null;
    }
}
